/**
 * Common function.
 * Date: 2015/04/03.
 */
// Define console in ie browwer.
(function () {
	try {
		return window.console;
	} catch (err) {
		return (window.console = {});
	}
})();
// Define global object.
(function () {
	// Define base object.
	var root = this,
	VAM = root.VAM = {};
	VAM.uuid = '__VAM__DSP__';
	VAM.lang = VAM.lang || {};
	root[VAM.uuid] = root[VAM.uuid] || {};
	(function () {
		var uuid = root[VAM.uuid];
		uuid._counter = uuid._counter || 1;
		VAM.lang.uuid = function () {
			return VAM.uuid + (uuid._counter++).toString(36);
		};
	})();
	root[VAM.uuid]._instances = root[VAM.uuid]._instances || {};
})();
// Define value poll function.
(function (VAM) {
	VAM.varPoll = VAM.varPoll || {};
	VAM.setVar = function (key, value) {
		if (VAM.varPoll.hasOwnProperty(key)) {
			throw ['VAM:', key, ' is already defined.'];
		};
		VAM.varPoll[key] = value;
	};
	VAM.getVar = function (key) {
		return VAM.varPoll[key];
	};
	VAM.setRoot = function (path) {
		if (VAM.hasOwnProperty('root')) {
			throw ['VAM:', 'root path is already defined.'];
		};
		VAM.root = path;
	};
	VAM.getRoot = function () {
		if (VAM.hasOwnProperty('root')) {
			return VAM.root;
		};
		throw ['VAM:', 'root path is not defined.'];
	};
	VAM.getViewport = function() {
		var e = window, a = 'inner';
    if (!('innerWidth' in window)) {
      a = 'client';
      e = document.documentElement || document.body;
    }
    return {
      width: e[a + 'Width'],
      height: e[a + 'Height']
    }
	};
	VAM.print = function(msg) {
		return typeof console !== 'undefined' && console.log !== null ? console.log(msg):void 0;
	};
	VAM.backRoot = function(data) {
		var backUrl = '/';
		if (data.status === 'sessionExpire') {
			window.location.href = backUrl;
		};
	};
})(VAM);
// Define global function extends.
(function (VAM) {
  VAM.fn = VAM.fn || {};
})(VAM);